package com.ainge.easystudy.designpattern.strategy;

import java.util.Arrays;

/**
 * 支付类型枚举
 *
 * @author: Ainge
 * @Time: 2021/4/25 20:17
 */
public enum PayType {

    ALIPAY("支付宝", "alipay"),
    Wechatpay("微信支付", "wechatpay"),
    UNIONPAY("银联支付", "unionpay"),
    JDPAY("京东白条", "jdpay");

    /**
     * 名称
     */
    private final String name;
    /**
     * 支付编码
     */
    private final String code;

    PayType(String name, String code) {
        this.name = name;
        this.code = code;
    }


    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    /**
     * 获取PayType
     * @param code 编码
     * @return 获取不到返回null
     */
    public static PayType getPayTypeByCode(String code){
        return Arrays.stream(PayType.values()).filter(payType -> payType.code.equalsIgnoreCase(code)).findAny().orElse(null);
    }
}
